package com.example.ercmssystem2.service;

import com.example.ercmssystem2.entity.Event;
import com.example.ercmssystem2.entity.EventType;
import com.example.ercmssystem2.entity.User;
import com.example.ercmssystem2.entity.EventResponse;
import com.example.ercmssystem2.entity.EventResource;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface EventService {
    
    Event saveEvent(Event event);
    
    Event findById(Long id);
    
    List<Event> findAllEvents();
    
    List<Event> findByStatus(String status);
    
    List<Event> findByEventType(EventType eventType);
    
    List<Event> findByReporter(User reporter);
    
    List<Event> findByHandler(User handler);
    
    List<Event> findEventsInTimeRange(LocalDateTime start, LocalDateTime end);
    
    List<Event> findByStatusAndPriority(String status, String priority);
    
    void deleteEvent(Long id);
    
    Event updateEventStatus(Long id, String status);
    
    Event assignHandler(Long id, User handler);
    
    Event assignEvent(Long eventId, Long handlerId, List<Long> resourceIds);
    
    Event updateEventProgress(Long eventId, String progress, String status);
    
    List<EventResponse> getEventProgressHistory(Long eventId);
    
    void sendEventNotification(Event event, String message, String type);
    
    void assignResourcesToEvent(Long eventId, List<Long> resourceIds, Long assignerId);
    
    void removeResourceFromEvent(Long eventId, Long resourceId);

    List<com.example.ercmssystem2.entity.Resource> findResourcesByEventId(Long eventId);
    
    List<EventResource> getResourceHistoryByEventId(Long eventId);

    List<EventResource> findCurrentEventResources(Long eventId);

    // 终端用户操作相关方法
    // 接受任务
    Event acceptEvent(Long eventId, Long responderId);
    
    // 开始前往现场
    Event startEnRoute(Long eventId, Long responderId, Double latitude, Double longitude);
    
    // 到达现场
    Event arriveAtScene(Long eventId, Long responderId, Double latitude, Double longitude);
    
    // 开始处置
    Event startProcessing(Long eventId, Long responderId);
    
    // 完成任务
    Event completeEvent(Long eventId, Long responderId, String completionNotes);
    
    // 开始返程
    Event startReturning(Long eventId, Long responderId);
    
    // 更新位置
    Event updateLocation(Long eventId, Long responderId, Double latitude, Double longitude);
    
    // 更新安全状态
    Event updateSafetyStatus(Long eventId, Long responderId, String safetyStatus);
    
    // 请求支援
    Event requestSupport(Long eventId, Long responderId, String supportType, String description);
    
    // 取消支援请求
    Event cancelSupportRequest(Long eventId, Long responderId);
    
    // 发送SOS
    Event sendSOS(Long eventId, Long responderId, String message);
    
    // 查询方法
    List<Event> getUserEvents(Long responderId);
    
    List<Event> getUserActiveEvents(Long responderId);
    
    Optional<Event> getCurrentActiveEvent(Long responderId);
    
    List<Event> getEventsNeedingAttention();
    
    List<Event> getOverdueEvents();
    
    // 统计方法
    Map<String, Object> getUserEventStatistics(Long responderId);
    
    Map<String, Object> getEventPerformanceStatistics(Long eventId);
    
    // 获取事件时间线
    List<Map<String, Object>> getEventTimeline(Long eventId);
    
    // 获取事件响应统计
    Map<String, Object> getEventResponseStatistics(Long eventId);
    
    // 检查事件是否可以自动关闭
    boolean canAutoCloseEvent(Long eventId);
    
    // 自动关闭事件
    void autoCloseEvent(Long eventId);
    
    // 任务重新分配
    Event reassignEvent(Long eventId, Long newResponderId, String reason);
    
    // 事件升级
    Event escalateEvent(Long eventId, String escalationReason);
    
    // 批量更新状态
    List<Event> batchUpdateStatus(List<Long> eventIds, String status);
    
    // 获取事件历史
    List<Event> getEventHistory(Long responderId, LocalDateTime start, LocalDateTime end);
    
    // 导出事件报告
    byte[] exportEventReport(Long eventId);
    
    // 导出用户事件历史
    byte[] exportUserEventHistory(Long responderId, LocalDateTime start, LocalDateTime end);
    
    // 获取用户历史任务
    List<Event> getUserEventHistory(Long responderId);
    
    // 获取用户已完成任务
    List<Event> getUserCompletedEvents(Long responderId);
    
    // 获取用户今日完成任务
    List<Event> getUserTodayCompletedEvents(Long responderId);
    
    // 坐标相关方法
    boolean hasValidCoordinates(Long eventId);
    
    // 获取最新响应者位置
    String getLatestResponderLocation(Long eventId);
    
    // 获取所有响应者位置
    List<Map<String, Object>> getAllResponderLocations(Long eventId);
    
    // ========== 统计分析相关方法 ==========
    
    /**
     * 获取事件概览统计
     */
    Map<String, Object> getEventOverviewStatistics(LocalDateTime start, LocalDateTime end);
    
    /**
     * 获取事件趋势统计
     */
    Map<String, Object> getEventTrendStatistics(LocalDateTime start, LocalDateTime end, String period);
    
    /**
     * 获取响应效率统计
     */
    Map<String, Object> getResponseEfficiencyStatistics(LocalDateTime start, LocalDateTime end);
    
    /**
     * 获取地理分布统计
     */
    Map<String, Object> getGeographicDistributionStatistics(LocalDateTime start, LocalDateTime end);
} 